<template>
    <!--index.wxml-->
    <view class="page">

        <view class="head-part">
            <image src="https://oss.qmxip.com/flash_goods/1085563945834180608.png" class="userBg"></image>
            <view class="userinfo">
                <!-- <view class="user-border">
                    <view class="user-border user-border-2">
                        <image class="userinfo-avatar" :src="avatarUrl" mode="cover"></image>
                    </view>
                </view>
                <text class="userNickName" v-if="userId">{{wechatInfo.nickname}}</text>
                <text class="userNickName" v-else @click="goLogin" data-key='add'>请点击登录</text> -->
                <UserHead/>
            </view>
        </view>

        <view class="center-box">

            <view class="col-item"  @click="goShopOrder('15')">
                <view class="l">
                    <text class="icon-chushen iconfont col-h f32" >  </text>
                </view>
                <view class="m">待配送 <text class="num ml5">{{ staticSendNums.dpsNum }}</text></view>
                <image class="r" src="/static/images/user/more.png" mode='aspectFit'></image>
            </view>
            <view class="col-item"  @click="goShopOrder('20')">
                <view class="l">
                    <text class="icon-chushen iconfont col-h f32" >  </text>
                </view>
                <view class="m">配送中 <text class="num ml5">{{ staticSendNums.pszNum }}</text></view>
                <image class="r" src="/static/images/user/more.png" mode='aspectFit'></image>
            </view>
            <view class="col-item"  @click="goShopOrder('25')">
                <view class="l">
                    <text class="icon-chushen iconfont col-h f32" >  </text>
                </view>
                <view class="m">已完成 <text class="num ml5">{{ staticSendNums.ywcNum }}</text></view>
                <image class="r" src="/static/images/user/more.png" mode='aspectFit'></image>
            </view>
            <view class="col-item"  @click="testMessage">
                <image class="l" src="/static/images/user/notice.png" mode='aspectFit'></image>
                <view class="m">消息提醒授权 <text class="num ml5"></text></view>
                <image class="r" src="/static/images/user/more.png" mode='aspectFit'></image>
            </view>

        </view>
    </view>
</template>
<script>

import WxPushMessage from '../../utils/message.js'
import UserHead from '../../components/UserHead'
const app = getApp();
export default {
    components: { UserHead },
    data () {
        return {
            showAuthorize:false,
            staticSendNums:{}, //配送人员 超市和快递一起的
        }
    },
    computed:{
        userInfo(){ return this.$store.getters.userInfo},
        wechatInfo(){ return this.$store.getters.wechatInfo},
        avatarUrl(){ return this.$store.getters.headimgurl},
    },
    watch:{
       
    },
    onShow(){
        // console.log('999999999999999',this.wechatInfo)

        // WxPushMessage.initType( 3 ,( bool )=>{

        //     console.log('申请消息',bool )

        // },true)

        this.initSendStatic()
      
    },
    mounted () {

      

    },
    methods: {
        goShopOrder (code) {

            this.$goNext('./shop-order?status='+code)
        },
        goExpressOrder(code){
            this.$goNext('./express-order?status='+code)
        },
    
        initSendStatic(){

            this.$axios('flash/supermarket/statistics/express/order/status')
                .then( res =>{

                    // console.log('看看配送数据  超市和快递一起的',res)

                    this.staticSendNums = res.data

                })

        },
        testMessage(){
            WxPushMessage.initType( 3 ,( bool )=>{

                // console.log('申请消息',bool )

                let that = this
                
                if(bool == 4){

                    uni.showToast({title:'消息功能正常'})
                }
                else{

                    WxPushMessage.authorizationBtn( 3 ,( authType ) =>{

                        if(authType != 3){

                            uni.showModal({
                                title: '授权失败',
                                content: '注意：授权失败将不能接受消息提示，请打开授权',
                                cancelText: '不需要',
                                confirmText: '授权',
                                success: function (res) {
                                    if (res.confirm) {
                                        
                                        that.testMessage()
                                        
                                    }
                                }
                            });
                        }

                    })
                }

            },true)
        },
         //下拉刷新
         onPullDownRefresh () {

            //强制更新一次
            app.forceRefresh(( bool ) => {

                if(!bool){
                    this.initSendStatic()
                }

                uni.stopPullDownRefresh();//停止刷新

            })
            },
    }
}
</script>
<style lang="scss" scoped>
.page{
    box-sizing: border-box;
    min-height: 100vh;
    background-color: #efefef;
}
.head-part{
  height:  500rpx;
  position: relative;
}
.head-part .userBg{
  width: 100%;
  height: 100%;
}
.userinfo {
  display: flex;
  flex-direction: column;
  align-items: center;
  color: #f1f1f1;
  position: absolute;
  z-index: 10;
  left: 0;
  top: 30%;
  width: 100%;
}
.user-border{
  border: 1px solid rgba(255, 255, 255, .4);
  padding: 12rpx;
  display: inline-block;
  border-radius: 50%;
}
.user-border-2{
  border-color: rgba(255, 255, 255, .8);
  padding: 8rpx;
}
.userinfo-avatar {
  overflow: hidden;
  width: 144rpx;
  height: 144rpx;
  /* margin: 20rpx; */
  border-radius: 50%;
}
.userNickName{
  margin-top: 20rpx;
}
.center-box{
  box-sizing: border-box;
  position: relative;
  top: -80rpx;
  margin: 0 32rpx;
  background-color: #fff;
  border-radius: 14rpx;
  min-height: 59vh;
  padding: 20rpx 20rpx;
}
.col-item{
  padding: 28rpx 10rpx;
  display: flex;
  align-items: center;
  color: #666;
  border-bottom: 1rpx solid #f1f1f1;
  font-size: 28rpx;
  margin-top: 20rpx;
}
.col-item .l{
  width:32rpx;
  height: 32rpx;
  margin-right: 30rpx;
  opacity: .5;
}
.col-item .m{
  flex: 1;
  font-weight: 500;
  font-family:"oswald", "SourceHanSansSC-Light","Source-Han-Light","Source Han Sans CN","SourceHanSansCN-Light","webfontSourceHanSansSC";
}
.col-item .r{
  width:30rpx;
  height: 30rpx;
  opacity: .2;
}
</style>